-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Protocol conformance cache for generic types #82818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@swift-ci please test |
@swift-ci Please benchmark |
712d217
to
645d438
Compare
@swift-ci please test |
@swift-ci please smoke test |
@swift-ci please test macOS |
645d438
to
e42a0e0
Compare
@swift-ci please test |
@swift-ci please smoke test macOS |
e42a0e0
to
6b0c1ec
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Nice idea. Hopefully the memory impact is small, should be if there are on average many generic types used for a given descriptor. I left a few very minor comments, but overall this looks really good.
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the same conformance can be reused across different instantiations of the generic type. Key changes: - Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing multiple insertions under a single lock - Add type descriptor-based caching for protocol conformances - Add environment variables for controlling and debugging the conformance cache - Add tests to verify the behavior of the conformance cache - Fix for swiftlang#82889 The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR` environment variable, which is enabled by default.
6b0c1ec
to
7989dbe
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Windows |
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the same conformance can be reused across different instantiations of the generic type.
Key changes:
GetOrInsertManyScope
class toConcurrentReadableHashMap
for performing multiple insertions under a single lockThe implementation is controlled by the
SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR
environment variable, which is enabled by default.Here are some numbers for a synthetic example:
On
main
:On the PR branch with the feature disabled:
On the PR branch with the feature enabled: